<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
// 引入自定义规则所需类 （Validator 其实只是别名，在config/app.php中定义的）
use Validator;
class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        //自定义表单phone验证规则
        // 参数1 phone 规则名
        Validator::extend('phone', function ($attribute, $value, $parameters, $validator) {
            $reg = '/^((\+?86-?)|(\(\+86-?\)))?1\d{10}$/';
            return preg_match($reg,$value);
        });
    }
}
